<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function sumInput() {
        const arr = []; //保存用户输入的数字
        while (true) {
          const num = prompt("number?");
          if (num === null || num === "" || isFinite(num) === false) {
            break;
          }
          arr.push(+num);
        }

        // 数组求和
        let sum = 0;
        for (let v of arr) {
          sum += v;
        }
        return sum;
      }
      console.log(sumInput());
    </script>
  </body>
</html>
